package com.juyu.miliao.api.util;

import java.util.List;

import com.juyu.miliao.api.domain.Grade;

public class GradeUtil {
	
	//计算土豪、魅力等级
	public static String getGradeCount(List<Grade> gradeList, int sum) {
		String temp = "0";
		for (int i = 0; i < gradeList.size(); i++) {
			if(sum<gradeList.get(i).getSum()){
				if(i==0)
					temp = gradeList.get(i).getGrade();
				else
					temp = gradeList.get(i-1).getGrade();
				break;
			}
			if(sum==gradeList.get(i).getSum()){
				temp = gradeList.get(i).getGrade();
			}
		}
		return temp;
	}

	public static Grade getGradeInfoByCount(List<Grade> gradeList, int sum) {

		for (int i = 0; i < gradeList.size(); i++) {
			if(sum<gradeList.get(i).getSum()){
				if(i==0) {
					Grade grade = gradeList.get(i);
					return grade;
				}
				else {
					Grade grade = gradeList.get(i - 1);
					return grade;
				}

			}
			if(sum==gradeList.get(i).getSum()){
				Grade grade = gradeList.get(i);
				return grade;
			}else if (sum>gradeList.get(i).getSum()&& i == gradeList.size()-1){
				return gradeList.get(gradeList.size()-1);
			}
		}

		return null;
	}
	
	//计算土豪、魅力下一等级要求值
	public static int getGradeNextSum(List<Grade> gradeList, int sum) {
		int temp = gradeList.get(1).getSum();
		for (int i = 1; i < gradeList.size(); i++) {
			if(sum<=gradeList.get(i).getSum()){
				temp = gradeList.get(i).getSum();
				break;
			}
		}
		return temp;
	}
}
